import { create } from 'zustand'
import { persist } from 'zustand/middleware'

interface UserInfo {
  id: number
  username: string
  nickname: string
  role: string
  status: string
  avatar: string | null
}

interface UserState {
  userInfo: UserInfo | null
  setUserInfo: (user: UserInfo) => void
  clearUserInfo: () => void
}

export const useUserStore = create<UserState>()(
  persist(
    set => ({
      userInfo: null,
      setUserInfo: user => set({ userInfo: user }),
      clearUserInfo: () => set({ userInfo: null })
    }),
    {
      name: 'user-storage'
    }
  )
)
